package igor.mass;

import igor.mass.model.AndroidCommand;
import igor.mass.model.AndroidDevice;
import igor.mass.model.AndroidRoom;
import android.R.integer;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ExpandableListView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RoomActivity extends Activity implements OnClickListener{
	private ExpadableAdapter mAdapter;
	private ExpandableListView commandsList;
	AndroidRoom room;

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        Bundle extras =getIntent().getExtras();
        
        room = (AndroidRoom) extras.getSerializable("room");
        
    	//LinearLayout LL_Dynamic = (LinearLayout) findViewById(R.id.LL_Dynamic);
        //setContentView(android.R.id.tabcontent);
    	FrameLayout fl = (FrameLayout) findViewById(android.R.id.tabcontent);
    	LayoutParams LP = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 

    	commandsList = new ExpandableListView(this);
    	mAdapter = new ExpadableAdapter(this, room);
    	commandsList.setAdapter(mAdapter);
    	commandsList.setGroupIndicator(null);
    	commandsList.setBackgroundResource(R.color.background);
    	int[] parentColors = {0xFF252525, 0xFFFF4848, 0xFF252525}; 
    	commandsList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, parentColors));
    	int[] childColors = {0xFF323232, 0xFFFF4848, 0xFF323232}; 
    	commandsList.setChildDivider(new GradientDrawable(Orientation.RIGHT_LEFT, childColors));
    	commandsList.setDividerHeight(1);
    	commandsList.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);
    	commandsList.setCacheColorHint(0x00);
    	commandsList.setScrollContainer(false);
    	
    	setContentView(commandsList, LP);
    	//fl.addView(commandsList);
    }
    
    @Override
    public void onClick(View v) {
    	int deviceIndex = (Integer)v.getTag(R.id.device);
    	int commandIndex = (Integer)v.getTag(R.id.command);
    	Intent intent = new Intent(this,CommandActivity.class);
    	AndroidDevice device = room.devices.get(deviceIndex);
    	AndroidCommand command = device.commands.get(commandIndex);
    	
    	intent.putExtra("room", room);
    	intent.putExtra("device", device);
    	intent.putExtra("command", command);
    	startActivity(intent);
    	
    	
    }

}
